$(
    function() {
        /*
           用户注册
           1.给那个注册按钮添加点击事件
           2.获取到用户输入框注册信息
           3.对用户的输入的信息进行简单的验证
           4.调用注册接口
           5.注册成功了 给出提示
           6.跳转到登录页面
        */
        $("#register-btn").on("tap", function() {
            console.log("点击成功");
            // var username =$.trim($("[name='username']").val())
            let username = $.trim($("[name='username']").val());
            let mobile = $.trim($("[name='mobile']").val());
            let password = $.trim($("[name='password']").val());
            console.log("password" + password);
            let againpassword = $.trim($("[name='againpassword']").val());
            console.log("againpassword" + againpassword);
            let vCode = $.trim($("[name='vCode']").val())
                // let vCode = $.trim($("[name='vCode']").val());

            if (!username) { mui.toast("请输入用户名"); return; }
            if (!/^1\d{10}/.test(mobile)) { mui.toast("请输入合法的手机"); return; }
            if (password != againpassword) { mui.toast("两次密码不一致"); return; }
            // if (!/^\d{6}$/.test(vCode)) { mui.toast("请输入合法验证码"); return; }
            console.log("vCode" + vCode);
            if (!/^\d{6}$/.test(vCode)) {
                mui.toast("请输入正确的认证码")
                return
            }

            $.ajax({
                url: '/user/register',
                type: "post",
                data: {
                    username: username,
                    mobile: mobile,
                    password: password,
                    vCode: vCode
                },
                success: function(res) {
                    console.log(res);
                    mui.toast("注册成功")
                    setTimeout(function() {
                        location.href = 'login.html'
                    }, 2000)


                }
            })

        })

        $("#vCode").on("tap", function() {
            $.ajax({
                url: '/user/vCode',
                type: "get",
                success: function(res) {
                    console.log(res.vCode);
                }
            })
        })

    }
)